package com.baidu.calculation_test.ui

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.baidu.calculation_test.R
import com.baidu.calculation_test.data.AppDatabase
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

class HistoryActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_history)
        val recycler = findViewById<RecyclerView>(R.id.recyclerHistory)
        val adapter = HistoryAdapter()
        recycler.layoutManager = LinearLayoutManager(this)
        recycler.adapter = adapter

        val dao = AppDatabase.get(this).historyDao()
        lifecycleScope.launch {
            dao.observeAll().collectLatest { list ->
                adapter.submitList(list)
            }
        }
    }
}


